package com.imon.sort;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;

public class NumbersFileReader implements Iterable<String> {

	private BufferedReader	bufferedReader	= null;

	public NumbersFileReader(File aFile) {
		try {
			bufferedReader = new BufferedReader(new FileReader(aFile));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	public void close() {
		try {
			bufferedReader.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public Iterator<String> iterator() {
		return new FileIterator();
	}

	class FileIterator implements Iterator<String> {
		private String	currentLine;

		public boolean hasNext() {
			try {
				currentLine = bufferedReader.readLine();
			} catch (IOException e) {
				currentLine = null;
				e.printStackTrace();
			}

			return currentLine != null;
		}

		public String next() {
			return currentLine;
		}

		public void remove() {
			// TODO Auto-generated method stub
		}
	}

}
